<!--
 * @name score
 * @description 组件描述
 * @author idouya
 * @email elegentfrog@163.com
 * @date 2025-07-03
 -->

<template>
  <div class="p-score common-bg common-layout">
    <page-title
      :discipline="gameInfo.discipline"
      :event="gameInfo.event"
      :match="gameInfo.match"
      :type="gameInfo.type"
      :eventName="gameInfo.eventName"
      :startTime="gameInfo.startTime"
      :showTime="true"
    ></page-title>
    <div class="content">
      <div class="content-top">
        <div class="line1">
          <div class="order">{{ atheleteInfo?.Order }}</div>
          <div class="name">{{ atheleteInfo?.AthleteName }}</div>
          <div class="club">{{ atheleteInfo?.CountryName }}</div>
        </div>
        <div class="line1">
          <div class="order horseOrder">{{ atheleteInfo?.HorseOrder }}</div>
          <div
            class="name horseName"
            :class="[atheleteInfo?.HorseName?.length > 12 ? 'horseNameAdapt' : '']"
          >
            {{ atheleteInfo?.HorseName }}
          </div>
          <!-- <div class="line1-time">
            <div class="time">
              {{ atheleteInfo.time }}
            </div>
          </div> -->
        </div>
        <!-- <div class="line3">
          <div class="item" v-for="(item, index) in process" :key="index">
            <div>({{ item.order }})</div>
            <div>{{ item.name }}</div>
          </div>
        </div> -->
      </div>
      <div class="content-bottom"></div>
    </div>
  </div>
</template>

<script setup>
import Storage from '@/assets/js/storage'
import Utils from '@/assets/js/utils'
import Config from '@/assets/js/config'
import { useMultiProcRequest } from '@/assets/js/useMultiProcRequest'

const { results, fetchForProcs } = useMultiProcRequest()

const gameInfo = ref({
  discipline: '马术',
  match: '',
  event: 'EVENTEAM',
  type: '实时成绩',
  startTime: '13:01:29',
})

const atheleteInfo = ref({
  Order: 1,
  AthleteName: '杨舒涵',
  CountryName: '中国',
  HorseOrder: 201,
  horHorseNameseName: 'Joanna',
})

const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()

onBeforeMount(() => {})
onMounted(async () => {
  params.value = route.query
  procName.value = Config.procNameList[route.name]
  await getData()
})

const getData = async () => {
  if (procName.value.length > 0) {
    await fetchForProcs(procName.value, {
      procName: procName.value[0],
      keyValues: params.value,
    })
  }
}

watchEffect(() => {
  if (results.value?.recordset) {
    gameInfo.value.event = results.value.recordset[0]?.EventCode
    gameInfo.value.match = results.value.recordset[0].MatchName
    gameInfo.value.eventName = results.value.recordset[0]?.EventName
    atheleteInfo.value = results.value.recordset[0]
  }
})

watch(
  () => route.query,
  (val) => {
    params.value = val
    getData()
  }
)
</script>

<style scoped lang="scss">
@import '@/assets/scss/dressage/score1';
</style>
